﻿namespace NTLib.Pipe.Network.UTest.Http
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using NTLib.Pipe.Network.Descriptors;
    using NTLib.Pipe.Targets;
    using NTLib.Core.Tasks;

    using System;
    using System.Linq;
    using NTLib.Pipe.Network.Messages;
    using System.Threading;
    using System.Net;
    using NTLib.Pipe.Network.Targets;
    using NTLib.Pipe.Network.Providers;

    [TestClass]
    public class HttpSimpleUTest
    {
        #region Fields

        private NetworkPipeProvider _prov;

        #endregion

        #region Methods

        [TestInitialize]
        public void Initialize()
        {
            TargetManager.Instance.Register(HttpNetworkTargetProvider.Instance);

            _prov = new NetworkPipeProvider();
            PipeManager.Instance.Register(_prov);
        }

        [TestCleanup]
        public void Unload()
        {
            PipeManager.Instance.UnRegister(this._prov);
        }

        [TestCategory("Pipe.Network.Http")]
        [TestMethod]
        public void SimpleHttpPipe()
        {
            throw new NotImplementedException();
            //CancellationTokenSource source = new CancellationTokenSource();
            //source.CancelAfter(TimeSpan.FromSeconds(60));

            //HttpInfo info = new HttpInfo();
            //info.Uri = new Uri("http://ip.jsontest.com/");

            //var result = TargetManager.Instance.LocateAsync(info).WaitResult();

            //Assert.IsNotNull(result);
            //Assert.IsTrue(result.Count() > 0);

            //var pipe = PipeManager.Instance.CreateAsync<IHttpMessage>(result.First()).WaitResult();

            //var res = pipe.PushAsync<TestPackage>(null, source.Token).WaitResult(source.Token);

            //Assert.IsNotNull(res);
            //Assert.IsFalse(string.IsNullOrEmpty(res.Ip));
            //IPAddress ip = null;
            //Assert.IsTrue(IPAddress.TryParse(res.Ip, out ip));
        }

        #endregion
    }
}
